import time
import hashlib
from xmlrpc.client import ServerProxy, Transport, MultiCall, Fault
from transfer.config import get_config


ServerFault = Fault

class MyTransport(Transport):
    pass

class Client(object):

    def __init__(self):
        ip, port = get_config('client')
        self.remote = ServerProxy('http://%s:%s' % (ip, port),
                                  use_builtin_types=True,
                                  use_datetime=True,
                                  #verbose=True,
                                  allow_none=True)

    @property
    def system_methods_list(self):
        return self.remote.system.listMethods()

    def multi_call(self):
        return MultiCall(self.remote)

    def login(self, user, password):
        pwd = hashlib.md5()
        pwd.update(bytes(password,encoding='utf-8'))
        return self.remote.login(user,pwd.hexdigest())

client = Client()